OBJS = out/kernel.o out/main.o out/monitor.o out/common.o out/gdtidt.o out/interrupt.o out/isr.o out/timer.o \
	out/fifo.o out/kstdio.o out/nasmfunc.o out/stdio.o out/string.o out/memory.o

out/%.o : kernel/%.c
	i686-elf-gcc -c -I include -O0 -fno-builtin -fno-stack-protector -o out/$*.o kernel/$*.c

out/%.o : kernel/%.asm
	nasm -f elf -o out/$*.o kernel/$*.asm

out/%.o : lib/%.c
	i686-elf-gcc -c -I include -O0 -fno-builtin -fno-stack-protector -o out/$*.o lib/$*.c

out/%.o : lib/%.asm
	nasm -f elf -o out/$*.o lib/$*.asm

out/%.o : drivers/%.c
	i686-elf-gcc -c -I include -O0 -fno-builtin -fno-stack-protector -o out/$*.o drivers/$*.c

out/%.o : drivers/%.asm
	nasm -f elf -o out/$*.o drivers/$*.asm

out/%.o : fs/%.c
	i686-elf-gcc -c -I include -O0 -fno-builtin -fno-stack-protector -o out/$*.o fs/$*.c

out/%.o : fs/%.asm
	nasm -f elf -o out/$*.o fs/$*.asm

out/%.bin : boot/%.asm
	nasm -I boot/include -o out/$*.bin boot/$*.asm

out/kernel.bin : $(OBJS)
	i686-elf-ld -s -T kernel/linker.ld -o out/kernel.bin $(OBJS)

hd.img : out/boot.bin out/loader.bin out/kernel.bin
	ftimgcreate hd.img -t hd -size 80
	ftformat hd.img -t hd -f fat16
	ftcopy out/loader.bin -to -img hd.img
	ftcopy out/kernel.bin -to -img hd.img
	dd if=out/boot.bin of=hd.img bs=512 count=1

run : hd.img
	qemu-system-i386 -hda hd.img

clean :
	cmd /c del /f /s /q out

default : clean run